package com.itheima.service.impl;


import com.itheima.mapper.UserMapper;
import com.itheima.pojo.PageBean;
import com.itheima.pojo.User;
import com.itheima.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public PageBean<User> selectByPage(int currentPage, int pageSize) {
        int begin = currentPage;
        int size = pageSize;

        List<User> users = userMapper.selectByPage(begin, size);
        int total = userMapper.selectTotal();
        PageBean<User> userPageBean = new PageBean<User>();
        userPageBean.setRows(users);
        userPageBean.setTotalCount(total);
        return userPageBean;
    }

    @Override
    public int add(User user) {
        int i = userMapper.add(user);
        return i;
    }

    @Override
    public Integer deleteById(int id) {
        int i = userMapper.deleteById(id);
        return i;
    }

    @Override
    public int update(User user) {
        int i = userMapper.update(user);
        return i;
    }
}
